    add_hosts(){

            readarray -t  str < <(echo -e "127.0.0.1 host1\n127.0.0.2 host2")


            i=0
            while [ $i -lt ${#str[@]} ];do
                grep -q "${str[$i]}" /tmp/hosts 
                
                if [ $? -eq 0 ];then
                    echo "$(date "+%F %H:%M:%S")I! ${str[$i]} already in /etc/hosts, pass."
                else
                    echo "$(date "+%F %H:%M:%S")I!  ${str[$i]} will append to /etc/hosts."
                    sudo echo ${str[$i]} >>/tmp/hosts
                    grep -q "${str[$i]}" /tmp/hosts || echo "$(date "+%F %H:%M:%S")E! add ${str[$i]}to /etc/hosts failed!!!"
                fi

                i=$(($i+1))
            done
    }

    add_hosts